home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: passing arguments to main()
- Date: Wed, 06 Mar 96 22:07:47 GMT
- Organization: none
- Message-ID: <826150067snz@genesis.demon.co.uk>
- References: <4h78t1$nqq@netnews.upenn.edu> <4h7ql8$4rs@news.microsoft.com> <4hiqms$kg2@mother.usf.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4hiqms$kg2@mother.usf.edu> sanidas "BIO" writes:
-
- >I'm not sure I understand your question. I think you may want to look at the
- >two variables argc and argv. Declared like this:
- >
- >main(int argc, char* argv[])
- >{
- >/*C code here*/
- >
- >return;
- >}
- >
- >argc is an integer that counts the number of commands on the command line
-
- I assume you mean the number of command line arguments. A program is
- generally invoked by a single command.
-
- > (it
- >is always at least one because the executable file name counts as a command).
-
- The program name is counted in argc. However the C language allows argc
- to be 0 where there is neither a program name nor any command line arguments
- available. A partable C program will not assume that argc is nonzero.
-
- >argv is an array of pointers that point to a character array.
-
- argv is a pointer to the first element of an array of char * pointers.
- Each char * pointer points to the first element of an array of char whose
- contents is a string (i.e. a sequence of characters ending in the null
- character). The last pointer in the array of char * (i.e. argv[argc]) is a
- null pointer.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-